#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> coup, prod;
int main()
{
    int NC, NP;
    scanf("%d", &NC);
    int i, j;
    int tmp;
    for (i = 0; i < NC; ++i)
    {
        scanf("%d", &tmp);
        coup.push_back(tmp);
    }
    sort(coup.begin(), coup.end());
    scanf("%d", &NP);
    for (i = 0; i < NP; ++i)
    {
        scanf("%d", &tmp);
        prod.push_back(tmp);
    }
    sort(prod.begin(), prod.end());
    int total = 0;
    for (i = 0; i < NC && i < NP && coup[i] < 0 && prod[i] < 0; ++i)
    {//只要有匹配的正数就相乘并相加
        total += coup[i] * prod[i];
    }
    for (i = coup.size() - 1, j = prod.size() - 1; i >= 0 && j >= 0 && coup[i] > 0 && prod[i] > 0; --i, --j)
    {
        total += coup[i] * prod[j];
    }
    printf("%d\n", total);
    return 0;
}